home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / PowerD / powerd / examples / samplelibrary / source / sample.library.d
Text File  |  2002-10-28  |  3KB  |  147 lines

  1. /*****************************************************************/
  2.  
  3. OPT NOHEAD
  4.  
  5. MODULE 'exec',
  6.        'exec/execbase',
  7.        'exec/libraries',
  8.        'exec/nodes',
  9.        'exec/resident'
  10.  
  11. OBJECT LibBase
  12.   library :Library,
  13.   flags   :BYTE,
  14.   pad     :BYTE,
  15.   segment :BPTR
  16. /*
  17. here we could add a semaphore, pointers to library bases (dosbase etc.) etc.
  18. */
  19. ENDOBJECT
  20.  
  21. #define LibVersion 1
  22. #define LibRevision 0
  23. #define libname 'sample.library'
  24. #define LibCopyright(ver,rev) ' v ver.rev (\x3d) (C) Marco Antoniazzi'
  25.  
  26. DEF ExecBase
  27.  
  28. /* Add these if you PrintF() something
  29. DEF stdin,stdout
  30. */
  31.  
  32. /* Avoid execution and LibNull all in once */
  33. APROC LibNull()
  34.   move.l #0,d0
  35. ENDPROC
  36.  
  37. /* this static structure must be here. This is an AUTOINIT library */
  38. Romtag:
  39.   WORD RTC_MATCHWORD
  40.   LONG Romtag,EndRom
  41.   BYTE RTF_AUTOINIT,LibVersion,NT_LIBRARY,0
  42.   LONG LibName,LibIDString,LibInitTable
  43. EndRom:
  44.   WORD 0
  45.  
  46. /* the 4 magic LONGs for Autoinit libraries. */
  47. LibInitTable:
  48.   LONG SIZEOF_LibBase,LibVectors,LibData,LibInit
  49.  
  50. /* our functions. 1st 4 are fixed */
  51. LibVectors:
  52.   LONG LibOpen,LibClose,LibExpunge,LibNull
  53. /* Here we must add all the functions of our library, which must
  54. match exactly (also in the same order) those of the corrisponding .m file */
  55.   LONG Subtract
  56.  
  57.   LONG -1   /* terminator */
  58.   
  59. LibData:
  60.   BYTE $a0,8,9,0,$80,10   /* some "magic" numbers ;) */
  61.   LONG LibName
  62.   BYTE $a0,14,6,0,$90,20  /* more "magic" numbers ;) */
  63.   WORD LibVersion
  64.   BYTE $90,22             /* more "magic" numbers ;) */
  65.   WORD LibRevision
  66.   BYTE $80,24             /* more "magic" numbers ;) */
  67.   LONG LibIDString
  68.   LONG 0   /* terminator */
  69.  
  70. LibName:
  71.   BYTE libname,0
  72. LibIDString:      /* make the version string */
  73.   BYTE '$VER: ',libname,LibCopyright(LibVersion,LibRevision),0
  74.  
  75. PROC LibInit(base:PTR TO LibBase IN d0,segment IN a0)(PTR TO LibBase)
  76.  
  77.   base.segment:=segment
  78.     
  79.   IFN myInitLib(base)
  80.     LibExpunge(base)
  81.     base:=0
  82.   ENDIF
  83.  
  84. ENDPROC base
  85.  
  86. PROC LibOpen(base:PTR TO LibBase IN a6)(PTR TO LibBase)
  87.   
  88.   IFN myOpenLib(base) THEN RETURN 0
  89.   base.library.Flags &=~LIBF_DELEXP
  90.   base.library.OpenCnt++
  91.  
  92. ENDPROC base
  93.  
  94. PROC LibClose(base:PTR TO LibBase IN a6)(LONG)
  95.   
  96.   myCloseLib(base)
  97.   IFN --base.library.OpenCnt
  98.     IF base.library.Flags & LIBF_DELEXP THEN RETURN LibExpunge(base)
  99.   ENDIF
  100.  
  101. ENDPROC 0
  102.  
  103. PROC LibExpunge(base:PTR TO LibBase IN a6)(LONG)
  104.   DEF rc
  105.   
  106.   IF base.library.OpenCnt
  107.     base.library.Flags |=LIBF_DELEXP
  108.     RETURN 0
  109.   ENDIF
  110.   myExpungeLib(base)
  111.   Remove(base)
  112.   rc:=base.segment
  113.   FreeMem(base-base.library.NegSize,base.library.NegSize+base.library.PosSize)
  114.  
  115. ENDPROC rc
  116.  
  117. /* here we could open libraries, allocate some "global" memory ecc. */
  118. PROC myInitLib(base:PTR TO LibBase)(LONG)
  119. /*
  120.   IF OpenLibrary(...)
  121.     stdout:=Output() ; stdin:=Input()
  122.     RETURN TRUE
  123.   ENDIF
  124. */
  125. ENDPROC FALSE
  126.  
  127. PROC myOpenLib(base:PTR TO LibBase)(LONG)
  128. ENDPROC TRUE
  129.  
  130. PROC myCloseLib(base:PTR TO LibBase)(LONG)
  131. ENDPROC TRUE
  132.  
  133. /* here we could deallocate "global" memory ecc. */
  134. PROC myExpungeLib(base:PTR TO LibBase)
  135. /* no need to check for null conditions because it's done by the functions
  136.   CloseLibrary(...)
  137. */
  138. ENDPROC
  139.  
  140.  
  141. PROC Subtract(a IN d0,b IN d1)(LONG)
  142. ENDPROC a-b
  143.  
  144. /*****************************************************************/
  145.  
  146.  
  147.